package com.quiz.intent;

import android.os.Parcel;
import android.os.Parcelable;

import com.quiz.entities.Topic;

/**
 * 
 * @author long
 * Luu Topic bang Intent
 * phai implements Parcelable
 * 
 */
public final class IntentTopic implements Parcelable{
	static Topic topic;
	// cac phuong thuc sau bat buoc phai implement
	private IntentTopic(Parcel in) {
		readFromParcel(in);
	}
	
	public void readFromParcel(Parcel in) {
		topic.setId(in.readInt());
		topic.setTitle(in.readString());
		topic.setDescription(in.readString());
		topic.setCategory(in.readString());
	}
	
	public static Topic getTopic() {
		return topic;
	}
	
	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(topic.getId());
		out.writeString(topic.getTitle());
		out.writeString(topic.getDescription());
		out.writeString(topic.getCategory());
	}
	// very simple but must implement
	@Override
	public int describeContents(){
		return 0;
	}
	public static final Parcelable.Creator<IntentTopic> CREATOR = new Creator<IntentTopic>() {
		
		@Override
		public IntentTopic[] newArray(int size) {
			// TODO Auto-generated method stub
			return new IntentTopic[size];
		}
		
		@Override
		public IntentTopic createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			return new IntentTopic(source);
		}
	};	
	
}
